package com.moxiao.yfjh.module.blind.controller.admin.memberusertag;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.common.pojo.CommonResult;
import static com.moxiao.yfjh.framework.common.pojo.CommonResult.success;

import com.moxiao.yfjh.framework.excel.core.util.ExcelUtils;

import com.moxiao.yfjh.framework.operatelog.core.annotations.OperateLog;
import static com.moxiao.yfjh.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.moxiao.yfjh.module.blind.controller.admin.memberusertag.vo.*;
import com.moxiao.yfjh.module.blind.dal.dataobject.memberusertag.MemberUsertagDO;
import com.moxiao.yfjh.module.blind.convert.memberusertag.MemberUsertagConvert;
import com.moxiao.yfjh.module.blind.service.memberusertag.MemberUsertagService;

@Tag(name = "管理后台 - 相亲用户标签")
@RestController
@RequestMapping("/blind/member-usertag")
@Validated
public class MemberUsertagController {

    @Resource
    private MemberUsertagService memberUsertagService;

    @PostMapping("/create")
    @Operation(summary = "创建相亲用户标签")
    @PreAuthorize("@ss.hasPermission('blind:member-usertag:create')")
    public CommonResult<Long> createMemberUsertag(@Valid @RequestBody MemberUsertagCreateReqVO createReqVO) {
        return success(memberUsertagService.createMemberUsertag(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新相亲用户标签")
    @PreAuthorize("@ss.hasPermission('blind:member-usertag:update')")
    public CommonResult<Boolean> updateMemberUsertag(@Valid @RequestBody MemberUsertagUpdateReqVO updateReqVO) {
        memberUsertagService.updateMemberUsertag(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除相亲用户标签")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('blind:member-usertag:delete')")
    public CommonResult<Boolean> deleteMemberUsertag(@RequestParam("id") Long id) {
        memberUsertagService.deleteMemberUsertag(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得相亲用户标签")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('blind:member-usertag:query')")
    public CommonResult<MemberUsertagRespVO> getMemberUsertag(@RequestParam("id") Long id) {
        MemberUsertagDO memberUsertag = memberUsertagService.getMemberUsertag(id);
        return success(MemberUsertagConvert.INSTANCE.convert(memberUsertag));
    }

    @GetMapping("/list")
    @Operation(summary = "获得相亲用户标签列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('blind:member-usertag:query')")
    public CommonResult<List<MemberUsertagRespVO>> getMemberUsertagList(@RequestParam("ids") Collection<Long> ids) {
        List<MemberUsertagDO> list = memberUsertagService.getMemberUsertagList(ids);
        return success(MemberUsertagConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得相亲用户标签分页")
    @PreAuthorize("@ss.hasPermission('blind:member-usertag:query')")
    public CommonResult<PageResult<MemberUsertagRespVO>> getMemberUsertagPage(@Valid MemberUsertagPageReqVO pageVO) {
        PageResult<MemberUsertagDO> pageResult = memberUsertagService.getMemberUsertagPage(pageVO);
        return success(MemberUsertagConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出相亲用户标签 Excel")
    @PreAuthorize("@ss.hasPermission('blind:member-usertag:export')")
    @OperateLog(type = EXPORT)
    public void exportMemberUsertagExcel(@Valid MemberUsertagExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<MemberUsertagDO> list = memberUsertagService.getMemberUsertagList(exportReqVO);
        // 导出 Excel
        List<MemberUsertagExcelVO> datas = MemberUsertagConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "相亲用户标签.xls", "数据", MemberUsertagExcelVO.class, datas);
    }

}
